<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>瑞雪传奇</title>
	</head>
	<!-- <script src="./app/static/jquery/jquery-1.8.3.min.js"></script> -->
	<!-- <script src="./app/config/config.js"></script> -->
	<body>
		<iframe id="weburl" src="" frameBorder="0"  scrolling="no"></iframe>
	</body>
	<style>
		body {
			margin: 0;
			/* Reset default margin */
		}

		iframe {
			display: block;
			/* iframes are inline by default */
			background: #000;
			border: none;
			/* Reset default border */
			height: 100vh;
			/* Viewport-relative units */
			width: 100vw;
		}
	</style>
	
	<script>
// const path = require('path')
// // electron主进程：
// function getExtraFilesPath(filename){
//     return path.join(process.cwd(), `/app/${filename}`);
// }
// let filePath = getExtraFilesPath('static/config.js');
// console.log(filePath)
	var {
		_config
	} = require('../config/config.js');
	var {$} = require("../static/jquery/jquery-1.8.3.min.js");
	// 	// console.log(_config)
	// 	var {$} = require("./app/static/jquery/jquery-1.8.3.min.js");
		// var $ = require("jquery");
		// console.log($)
		var api=_config.updateApp
		var timestamp = parseInt(new Date().getTime()/1000);
		var weburl=localStorage.getItem("weburl") || _config.weburl || ""
		function start() {
			// console.log("请求准备发送");
			$.ajax({
				type: "POST",
				url:api+ "?device=win&t="+timestamp+"&v="+_config.v+"&appid="+_config.appid,
				dataType: "json",
				data: {device:"win"},
				success(res) {
					console.log(res)
					if(res.data){
						var code = res.code
						var data = res.data
						if ((data.v != _config.v || _config.appid != data.appid) && data.down){ 
							 window.location.href = data.down;
						}else if(data.weburl){
							localStorage.setItem("weburl",data.weburl)
							
							for (var i = 0; i < window.parent.frames.length; i++) {
								//window.parent.frames[i].location="http://w3cschool.cc";
								// console.log(data.url+"?t="+ timestamp)
								window.parent.frames[i].location = data.weburl+"?t="+timestamp
								
							}
						}else{
							$("title").text(data.title?data.title:_config.title);
							for (var i = 0; i < window.parent.frames.length; i++) {
								//window.parent.frames[i].location="http://w3cschool.cc";
								window.parent.frames[i].location = weburl;
							}
						}
					}

				},error:function () {
                    // alert("失败");
					for (var i = 0; i < window.parent.frames.length; i++) {
						//window.parent.frames[i].location="http://w3cschool.cc";
						window.parent.frames[i].location = weburl;
					}
                }

			})
		}
		start()
	</script>
</html>